﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Validity.Rules;
using Validity.Rules.Decorators;

namespace Validity.Test.Rules.Decorators
{
  [TestClass]
  public class RuleDecoratorTest
  {
    private readonly Mock<IRule<ObjectStub, IComparable>> _baseRule;
    private readonly ObjectStub _objectStub = new ObjectStub();
    private readonly IRule<ObjectStub, IComparable> _rule;

    public RuleDecoratorTest()
    {
      _baseRule = new Mock<IRule<ObjectStub, IComparable>>(MockBehavior.Strict);
      _rule = new RuleDecorator<ObjectStub, IComparable>(_baseRule.Object);
    }
    
    [TestMethod]
    public void TestIsViolatedByDelegated()
    {
      _baseRule.Setup(mock => mock.IsViolatedBy(_objectStub, "string")).Returns(false);

      Assert.IsFalse(_rule.IsViolatedBy(_objectStub, "string"));
    }

    [TestMethod]
    public void TestGetRuleViolationDelegated()
    {
      var violation = new RuleViolation("Violation");

      _baseRule.Setup(mock => mock.GetRuleViolation(_objectStub, "string")).Returns(violation);

      Assert.AreEqual(violation, _rule.GetRuleViolation(_objectStub, "string"));
    }
  }
}
